package com.lx.user.web;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.lx.bilibili.entity.User;
import com.lx.bilibili.entity.UserEx;
import com.lx.bilibili.entity.Video;
import com.lx.user.dao.UserExMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lx
 * @since 2025-03-26
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserExMapper userExMapper;

    @RequestMapping("searchUInfo")
    public UserEx searchUInfo(String searchText){
        LambdaQueryWrapper<UserEx> lqw = new LambdaQueryWrapper<>();
        lqw.like(UserEx::getName, searchText);
        lqw.orderByDesc(UserEx::getId);
        Page page = new PageDTO(1,1);
        List<UserEx> list = userExMapper.selectPage(page, lqw).getRecords();
        for(UserEx user : list){
            user.setVideoNum(userExMapper.getVideoNumById(user.getId()));
        }
        return list.get(0);
    }

    @RequestMapping("getVideoById")
    public List<Video> getVideoById(int id){
        return userExMapper.getVideoById(id);
    }


}
